const bt = require('./bt');

//二叉树的中序遍历(递归)
const inorder_1 = (root) => {
    if (!root) {return;}
    inorder_1(root.left);
    console.log(root.val);
    inorder_1(root.right);
};

inorder_1(bt);

//二叉树的中序遍历(非递归)
const inorder_2 = (root) => {
    if (!root) return;
    const stack = [];
    let p = root;
    //先把所有左子节点放入栈，再访问根节点，最后把右子节点放入栈
    while (stack.length || p){
        while(p){
            stack.push(p);
            p = p.left;
        }
        const n = stack.pop();
        console.log(n.val);
        p = n.right;
    }

}